/*******************************************************************************
* Homework 3: Main.cpp CSCE 240, Spring 2010
* Author: Andrew Shore
* Date Last Modified: 17 February 2010
*
* Description: Main function for Homework 3. Prompts user for the number of 
* students that went on the trip and then a while loop is ran that allows the 
* user to enter multiple trips as long as they don't enter 0 for the number of
* students otherwise computation ends.  The same array is used for multiple 
* trips it is just overwritten by the new values.  The maximum number of  
* students a user can enter is 100 per trip.  Error occurs if user enters a 
* negative value for the number of Students. Calls balanceExpenses function 
* for each trip.
*
* The program itself calculates what is needed to balance the trip expenses and
* determines what each student needs to do to correct how much they paid.
* Information is displayed in standard output. Explained thoroughly in Trip.cpp
* 
* Input: None
* Output: just a log of what occurs
*
* Includes header file 'Main.h'
*
*********************************************************************************/
#include "Main.h"


int main(){
   /*Variables:
       LENGTH - enumerated constant for max array size
       numberOfStudent - integer for taking in from standard input the number
                         of students going on the trip
       trip - instance of class trip to call balanceExpenses function
       students - array of doubles to hold what each student paid
   **/
   enum {LENGTH = 100};
   int numberOfStudents;
   Trip trip;
   double students[LENGTH];
 
   cout << "Welcome to the Trip program.\n";
 
   //loops until a 0 is input for the number of students, continues to call 
   //function for as many trips as needed
   while( numberOfStudents != 0 ){

      cout << "Please enter the number of students that went on the Trip:\n";
      cin >> numberOfStudents;

      //makes sure users enter a postive value for number of students
      if( numberOfStudents < 0){
         cout << "ERROR: illegal negative value";
         exit(1);
      }
      //breaks out of loop if 0 is input for number of students
      if( numberOfStudents == 0){
         break;
      }

      trip.balanceExpenses(students, numberOfStudents);
  
   }
  
   cout << "Thank you for using the Trip program. Goodbye.\n";

   return 0;
}
